<?php
/**
 * 智慧办公前台
 */
namespace app\index\common;

use service\RequestService;

use service\UtilService;
use think\Config;
use think\Controller;
use think\Db;
use think\Exception;
use think\Session;
use traits\controller\Jump;

class Homebase extends Controller
{
    protected static $homeuser_info;

    protected static $controller_name; //控制器名称
    protected static $mode_name; //模快名称
    protected static $action_name;//方法名称

    protected function _initialize(){
        parent::_initialize(); // TODO: Change the autogenerated stub
        $homeuser_info = Session::get("homeuser_info");
        if(empty($homeuser_info)){
            $this->redirect('/index/passport/login.html');
        }
        //$homeuser_info['id'] = 15053696;
        //$homeuser_info['id'] = 18832;
        //$homeuser_info['id'] = 3719;
        $homeuser_info = self::$homeuser_info = Db::name("user")->where(['id'=>$homeuser_info['id']])->find();
        //dump($homeuser_info);exit;
        if($homeuser_info['is_jtzb'] != 1){
            //exit("您不在集团总部，无法使用无卡通行功能！");
        }
        $this->assign("homeuser_info", self::$homeuser_info);
    }

    protected function AddsgLogs($describe,$msg_in = '',$msg_out = ''){
        if(empty($describe)){
            $describe="暂无描述";
        }
        $ars = ['describe' => $describe, 'type' => 4,  'admin_id' => self::$homeuser_info['id'], 'admin_name' => self::$homeuser_info['username'], 'browse' => UtilService::getBrowser(), 'ip' => UtilService::getip(), 'model' => self::$mode_name, 'controller' => self::$controller_name, 'action' => self::$action_name, 'create_time'=>time(),'time_formt'=>date("Y-m-d H:i:s")];
        $ars['msg'] = json_encode($this->request->request());
        $ars['msg_in'] = $msg_in;
        $ars['msg_out'] = $msg_out;
        $ars['server'] = json_encode($_SERVER,JSON_UNESCAPED_SLASHES);
        return Db::name("user_log")->insertGetId($ars);
    }

}
